-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add validator to ensure a contact person has email provided #235
Conversation
looks reasonable to me. we should add some tests. |
Provide the needed email for a contact person
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #235 +/- ##
==========================================
- Coverage 97.58% 91.81% -5.78%
==========================================
Files 16 16
Lines 1701 1722 +21
==========================================
- Hits 1660 1581 -79
- Misses 41 141 +100
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
6321238
to
6e7a3a2
Compare
@yarikoptic @satra I think this is good to go except that you may want to adjust the dandi-cli due to the change brought by this PR. |
@yarikoptic - should the CLI fail if this validation doesn't pass. i.e. do we force the user to adjust the metadata through the UI to fix validation issues and redownload the dandiset.yaml, before data can be uploaded? |
no, I do not think we anyhow concern ourselves with validity of the dedicated to that. This PR is pretty much orthogonal IMHO. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's simplify / shorten testing a bit. See individual comments.
Only loosely related to this PR (I guess) -- whenever we approach |
Using funcs to achieve this is unneeded
I don't know how at this point. I was actually thinking about this. The flexibility of the current arrangement comes from executing logic in Python defined as a validator for the |
in linkml you'd use rules so that would be something like this classes:
Person:
slots:
- role
- email
rules:
- preconditions:
slot_conditions:
role:
equals_string: ContactPerson
postconditions:
slot_conditions:
email:
required: true which we would need to modify the pydantic generator to support rules with validators to make @model_validator(mode='after')
def rule_0(self):
# some type inference would have to happen at generation time, but something like...
if self.role is not None and 'ContactPerson' in self.role:
assert self.email is not None
and then modify the pydantic model schema with {
"if": {
"properties": {"role": {"contains": { "const": "ContactPerson" }}},
},
"then": {
"properties": {"email": {"required": true }}
} but i think you're probably right that it would be cleaner to use a subclass with a type designator enums:
RoleName:
permissible_values:
ContactPerson:
classes:
Person:
attributes:
role:
range: RoleName
designates_type: true
email:
range: string
required: false
ContactPerson:
slot_usage:
email:
required: true and reconfigure pydanticgen to make use of discriminator in fields. |
when we get to linkml, let's separate out validation logic (which changes over time), from schema and schema-types which are likely more stable. this is also going to be relevant to partial models (before/after upload, before/after publish, etc.,.). |
good -- I think we are arriving at cleaner separation of "validation" against desired requirements vs "validation" of the model... as somewhat being also discussed in But as such I would take this PR as ready and merge it. |
This update is for meeting the requirement of having email for a contributor who is a contact person imposed by dandischema, dandi/dandi-schema#235
This PR provides a model level validator to ensures that a contributor acting as a contact person has an email provided per request of #189.